﻿Imports MySql.Data.MySqlClient
Public Class Form3

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MessageBox.Show("Le champ de l'ancien pseudo est vide .", "Changement de pseudo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        If TextBox2.Text = "" Then
            MessageBox.Show("Le champ du nouveau pseudo est vide .", "Changement de pseudo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        If TextBox2.Text = TextBox1.Text Then
            MessageBox.Show("L'ancien pseudo ne doit pas correspendre au nouveau .", "Changement de pseudo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        If Not TextBox1.Text = Base.Pseudo Then
            MessageBox.Show("Le pseudo ne corréspond pas à l'ancien pseudo .", "Changement de pseudo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        Else
            Dim RequeteSQL As String
            Dim objDataReader As MySqlDataReader
            RequeteSQL = "UPDATE Compte SET Pseudo = '" + TextBox2.Text + "' Where ID = " + Base.ID.ToString + " ;"
            Form4.objCommand = New MySqlCommand(RequeteSQL, Form4.Connection)
            objDataReader = Form4.objCommand.ExecuteReader
            objDataReader.Close()

            MessageBox.Show("Votre pseudo est changé avec succés !", "Inscription", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Hide()
            Base.Pseudo = TextBox2.Text
            Salaria.Pseudo.Text = "Bienvenue : " + TextBox2.Text
            Salaria.Show()
        End If
    End Sub

    Private Sub Form3_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Salaria.Show()
    End Sub
End Class